home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / bbsckit / bbsc.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  38KB  |  1,135 lines

  1. /*
  2.         bbsc.c
  3.  
  4.         BBS (Bulletin Board System) written in UNIX SYSTEM-III "C".
  5.  
  6.                 Support files needed:
  7.                         bbscdef.h
  8.                         bbscport.o or bbscport.c
  9.                         bbsclock.o or bbsclock.c
  10.                         bbscfile.o or bbscfile.c
  11.                         bbscmisc.o or bbscmisc.c
  12.  
  13.                                 Mike Kelly
  14.  
  15.         03/09/83 v1.0   written
  16.         07/07/83 v1.0   updated
  17. */
  18. #include "bbscdef.h"
  19.  
  20. #define LASTDATE  " 02/07/84 "
  21.  
  22. #define PGMNAME "BBSc    "
  23. #define VERSION " 1.1 "
  24.  
  25.  
  26. main()
  27.         {
  28.         int     i;
  29. /*
  30. *               init global variables
  31. */
  32.         debug   = FALSE;
  33.         statcnt = 0;
  34.         xpert   = FALSE;
  35.         active  = TRUE;
  36.  
  37.         w_fname[0] = '\0';
  38.         w_lname[0] = '\0';
  39.         strcpy(w_password,"MPK0");
  40.  
  41.         u_fname[0] = '\0';
  42.         u_lname[0] = '\0';
  43.         strcpy(u_password,"MPK0");
  44.         u_time1[0] = '\0';
  45.         u_date1[0] = '\0';
  46.         u_time2[0] = '\0';
  47.         u_date2[0] = '\0';
  48.         u_city[0]  = '\0';
  49.  
  50.         mm[0]    = '\0';
  51.         dd[0]    = '\0';
  52.         yy[0]    = '\0';
  53.         month[0] = '\0';
  54.         day[0]   = '\0';
  55.         year[0]  = '\0';
  56.         date[0]  = '\0';
  57.         week[0]  = '\0';
  58.         ttime[0] = '\0';
  59.  
  60.         strcpy(msg_delete,"0");
  61.         msg_no[0]   = '\0';
  62.         msg_date[0] = '\0';
  63.         msg_date[0] = '\0';
  64.         msg_time[0] = '\0';
  65.         msg_to[0]   = '\0';
  66.         msg_from[0] = '\0';
  67.         msg_pass[0] = '\0';
  68.         msg_subject[0] = '\0';
  69.         msg_text[0] = '\0';
  70.  
  71.         stop_that = FALSE;
  72.  
  73. /*       get date and time from the clock       */
  74.  
  75.         gettime(ttime);
  76.         getdate(mm,dd,yy,month,day,year,date,week);
  77.  
  78.         portinit() ;    /* init terminal modes */
  79.         signon()   ;
  80.         driver()   ;
  81.         portrst()  ;    /* undo any special modes */            
  82.         }
  83. /*      end of mainline routine         */
  84.  
  85. driver()
  86.         {
  87. char    linebuf[MAXLINE],
  88.         buf[128],
  89.         *bufptr,                /* ptr to buf */
  90.         usercd[100],            /* user record */
  91.         *userptr,               /* ptr to usercd */
  92.         cmd[2];
  93.  
  94. int     cnt,
  95.         ok_sw,
  96.         case_sw,
  97.         i,
  98.         num0,
  99.         num1,
  100.         num2;
  101.  
  102.         cnt     = 0;
  103.         ok_sw   = TRUE;
  104.         bufptr  = buf;
  105.         xpert   = FALSE;
  106.         cmd[0]  = '\0';
  107.  
  108.         while (active)
  109.                 {
  110.                 stop_that = FALSE ;             /* reset switch */
  111.                 portsout(CRLF);
  112.                 if (!xpert)
  113.                         {
  114.                         portsout("Commands: B,C,E,G,K,N,Q,R,S,W,X or ? ");
  115.                         }
  116.                 portsout("===> ");
  117.                 portsin(cmd,1);
  118.                 portsout(CRLF);
  119.  
  120.                 *cmd = toupper(*cmd) ;
  121.  
  122.                 switch (cmd[0])
  123.                         {
  124.                         case ('C'):             /* Unix */
  125.                                 cmd_c();
  126.                                 break;
  127.                         case ('E'):             /* enter msg */
  128.                                 cmd_e();
  129.                                 break;
  130.                         case ('G'):             /* goodby */
  131.                                 cmd_g();
  132.                                 break;
  133.                         case ('K'):             /* kill msg */
  134.                                 cmd_k();
  135.                                 break;
  136.                         case ('Q'):             /* quick scan */
  137.                                 cmd_q();
  138.                                 break;
  139.                         case ('R'):             /* read msg */
  140.                                 cmd_r();
  141.                                 break;
  142.                         case ('S'):             /* scan msg */
  143.                                 cmd_s();
  144.                                 break;
  145.                         case ('X'):             /* expert toggle */
  146.                                 cmd_x();
  147.                                 break;
  148.                         case ('N'):             /* print new-user stuff */
  149.                                 cmd_p(NEWUSER);
  150.                                 break;
  151.                         case ('W'):             /* print welcome file */
  152.                                 cmd_p(WELCOME);
  153.                                 break;
  154.                         case ('B'):             /* print bulletins */
  155.                                 cmd_p(BULLETINS);
  156.                                 break;
  157.                         case ('?'):             /* help */
  158.                                 cmd_p(HELP);
  159.                                 break;
  160.                         default:
  161.                                 break;
  162.                         }
  163.  
  164.                 }
  165.         }
  166. /*      end of function         */
  167.  
  168. cmd_g()                 /* good-by */
  169.         {
  170.         active = FALSE;
  171.         portsout("\r\nThanks for calling ");
  172.         portsout(w_fname) ;
  173.         portsout(CRLF)    ;
  174.         sleep(5)          ;             /* for the Smartmodem */
  175.         portsout("+")     ;             /* get the modems attention */
  176.         portsout("+")     ;             /* get the modems attention */
  177.         portsout("+")     ;             /* get the modems attention */
  178.         sleep(15)         ;                     /* for the Smartmodem */
  179.         gobble()          ;
  180.         portsout("ATH")   ;             /* hang up the phone */
  181.         portsout(CRLF)    ;
  182.         sleep(15)         ;                     /* for the Smartmodem */
  183.         }
  184. /*      end of function         */
  185.  
  186. cmd_c()                 /* go to the operating system level */
  187.         {
  188.         if ((inbuf=fopen(SYSTEM,"r")) == NULL)
  189.                 {
  190.                 portsout(CRLF) ;
  191.                 portsout("Exiting to the operating system level!") ;
  192.                 portsout(CRLF) ;
  193.                 }
  194.         else
  195.                 {
  196.                 porttype(inbuf);        /* type a file to port */
  197.                 close(inbuf);
  198.                 }
  199.         active = FALSE;
  200.         }
  201. /*      end of function         */
  202.  
  203. cmd_e()                 /* enter a message */
  204.         {
  205.         int     entering,
  206.                 editing,
  207.                 cnt1;
  208.         char    msg[50],
  209.                 l_cnt[3],
  210.                 ans[2];
  211.  
  212.         entering = editing = TRUE;
  213.         cnt1 = 0;
  214.         l_cnt[0] = '0';                 /* init line count */
  215.         msg_text[0] = '\0';             /* init message text area */
  216.  
  217.         portsout(CRLF);
  218.         portsout("This will be message # ");
  219.         portsout(h_next_msg);
  220.         portsout(CRLF);
  221.         portsout("                             ____.____1____.____2\r\n");
  222.         portsout("Who is the message for  ===> ");
  223.         portsin(msg_to,20);
  224.         portsout(CRLF);
  225.         portsout("What is the subject     ===> ");
  226.         portsin(msg_subject,20);
  227.         portsout(CRLF);
  228.  
  229.         portsout(CRLF) ;
  230.         portsout("A line can contain 40 characters, up to 20 lines.") ;
  231.         portsout(CRLF) ;
  232.         portsout("To end, enter a carriage return on an empty line.") ;
  233.         portsout(CRLF) ;
  234.         portsout(CRLF) ;
  235.         portsout("    .___.____1____.____2____.____3____.____4") ;
  236.         portsout(CRLF) ;
  237.  
  238.         while (entering)                /* get the text of the message */
  239.                 {
  240.                 linecnt(l_cnt);         /* calc line count */
  241.  
  242.                 portsout(l_cnt);        /* show line count */
  243.                 portsout("> ");         /*  and prompt */
  244.  
  245.                 portsin(msg,40);
  246.                 portsout(CRLF);
  247.  
  248.                 strcat(msg,"\n");       /* put a <lf> on each line */
  249.  
  250.                 if (strlen(msg) < 2)            /* count cr too */
  251.                         {
  252.                         entering = FALSE;       /* all done */
  253.                         }
  254.                 else
  255.                         {
  256.                         strcat(msg_text,msg);   /* append each line to text */
  257.                         }
  258.                 if ((++cnt1) > 19)              /* only allow 20 lines */
  259.                         {
  260.                         entering = FALSE;       /* all done */
  261.                         }
  262.                 }
  263.  
  264.         while (editing)         /* save it, fix it, list it, or get out */
  265.                 {
  266.                 portsout(CRLF);
  267.                 portsout("(S)ave,   (L)ist,   or (Q)uit") ;
  268.                 portsout(CRLF);
  269.                 portsout("(D)elete, (I)nsert, or (E)dit line ==> ") ;
  270.                 portsin(ans,1);                 /* get a byte */ 
  271.                 portsout(CRLF);
  272.  
  273.                 *ans = toupper(*ans) ;
  274.  
  275.                 switch (ans[0])                 /* get 1 byte */
  276.                         {
  277.                         case ('S'):             /* save message */
  278.                                 savemsg();
  279.                                 editing = FALSE; /* get out of while */
  280.                                 break;
  281.                         case ('E'):             /* edit message */
  282.                         case ('I'):             /* edit message */
  283.                         case ('D'):             /* edit message */
  284.                                 editmsg(*ans);
  285.                                 break;
  286.                         case ('L'):             /* list message */
  287.                                 listmsg();
  288.                                 break;
  289.                         case ('Q'):             /* get out w/out saving */
  290.                                 editing = FALSE; /* get out of while */
  291.                                 break;
  292.                         default:
  293.                                 portsout(CRLF);
  294.                                 portsout("Shall we try that one again?\r\n");
  295.                                 break;
  296.                         }       
  297.                 }
  298.  
  299.         }
  300. /*      end of function         */
  301.  
  302. linecnt(lcnt)                   /* 2 byte string of line numbers */
  303. char    *lcnt;
  304.         {
  305.         int     icnt;
  306.         char    xcnt[4];
  307.  
  308.         icnt = atoi(lcnt);
  309.         if (++icnt < 10)
  310.                 {
  311.                 strcpy(lcnt,"0");
  312.                 itoa(xcnt,icnt);
  313.                 strcat(lcnt,xcnt);
  314.                 }
  315.         else
  316.                 {
  317.                 itoa(xcnt,icnt);
  318.                 strcpy(lcnt,xcnt);
  319.                 }
  320.         return;
  321.         }
  322. /*      end of function         */
  323.  
  324. savemsg()                               /* save a message */
  325.         {
  326.         int     fd;
  327.  
  328.         portsout("Saving...\r\n");
  329.  
  330.         strcpy(msg_delete,"0");         /* delete byte */
  331.         strcpy(msg_date, mm);
  332.         strcat(msg_date,"/");
  333.         strcat(msg_date, dd);
  334.         strcat(msg_date,"/");
  335.         strcat(msg_date, yy);
  336.  
  337.         strcpy(msg_time,ttime);         /* and the time */
  338.  
  339.         strcpy(msg_from,w_fname);       /* and the from name */
  340.         strcat(msg_from," ");
  341.         strcat(msg_from,w_lname);
  342.  
  343.         portsout("Updating the message file...\r\n");
  344.         if ((fd = msgopen(2)) == ERROR)         /* open i/o */
  345.                 {
  346.                 return(ERROR);
  347.                 }
  348.         msgwrt(fd);             /* write the message */
  349.         msgclose(fd);
  350.  
  351.         strcpy(h_date,msg_date);
  352.         portsout("Updating the header  file...\r\n");
  353.         hdrwrt();               /* update the header file */
  354.         }
  355. /*      end of function         */
  356.  
  357.  
  358. listmsg()
  359.         {
  360.         char    *ptr,
  361.                 byte,
  362.                 lcnt[3];
  363.         int     i;
  364.  
  365.         ptr = msg_text;         /* ptr points to start of text */
  366.         lcnt[0] = '0';          /* start linecount at zero     */
  367.         
  368.         portsout(CRLF) ;
  369.         while (*ptr != 0)
  370.                 {
  371.                 linecnt(lcnt);
  372.                 portsout(lcnt);                 /* put out line number */
  373.                 portsout(">");
  374.                 while (byte = *ptr++)
  375.                         {
  376.                         if (byte == '\n')       /* we dont save <cr>, so add */
  377.                                 {               /*  it here when find a <cr> */
  378.                                 portsout(CRLF) ;
  379.                                 break ;
  380.                                 }
  381.                         else portout(byte) ;
  382.                         }
  383.                 }
  384.         }
  385. /*      end of function         */
  386.  
  387. editmsg(tflag) char tflag ;
  388.         {
  389.         char    ans[3] ;
  390.         int     lnum ;          /* line number to edit */
  391.  
  392.         while(1)
  393.                 {
  394.                 portsout(CRLF);
  395.                 portsout("Enter line number to ") ;
  396.                 if(tflag == 'E') portsout("edit,") ;
  397.                 else if(tflag == 'D') portsout("delete,") ;
  398.                 else if(tflag == 'I') portsout("insert after,") ;
  399.                 else return ;
  400.                 portsout(CRLF);
  401.                 portsout("   or RETURN to exit ==> ");
  402.                 portsin(ans,2);         /* only 20 lines possible */
  403.                 portsout(CRLF);
  404.                 lnum = atoi(ans);
  405.                 if (lnum <= 0)
  406.                         {
  407.                         break;          /* out of while and return */
  408.                         }
  409.                 if ((lnum < 20) || ((lnum == 20) && (tflag != 'I')))
  410.                         {
  411.                         editline(lnum,tflag) ; break ;
  412.                         }
  413.                 else                    /* else slap on hand and loop around */
  414.                         {
  415.                         portsout("Aw come on, there can only be 20 lines!");
  416.                         portsout(CRLF);
  417.                         portsout("Shall we try that again?");
  418.                         portsout(CRLF);
  419.                         }
  420.                 }               
  421.         }
  422. /*      end of function         */
  423.  
  424. editline(line_no,tflag)
  425. int line_no ; char tflag ;
  426.         {
  427.         char    work_msg[(20*40)+40],   /* work message area */
  428.                 *work_ptr,              /* pointers */
  429.                 *msg_ptr,
  430.                 *new_ptr,
  431.                 new_line[40+1],         /* new line to replace in text */
  432.                 byte ;
  433.         int     i ;                     /* a counter */
  434.  
  435.         work_msg[0] = '\0';             /* init strings */
  436.         new_line[0] = '\0';
  437.         i = 1 ;                         /* assume at line one */
  438.  
  439.         work_ptr = work_msg;    /* put the addr of work_msg in the pointer */
  440.         msg_ptr  = msg_text;    /* put the addr of the global message in ptr */
  441.         new_ptr  = new_line;    /* the new line too */
  442.  
  443.         while(byte = *msg_ptr)  /* if at the line then found it's start */
  444.                 {
  445.                 if(line_no == i) break ;        /* found the line        */
  446.                 while(byte = *msg_ptr++)        /* move msg to work area */
  447.                         {                       /*  until end of msg */
  448.                         *work_ptr++ = byte;
  449.                         if (byte == '\n')       /* end of line? */
  450.                                 {
  451.                                 i++ ; break ;   /* then stop moving */
  452.                                 }
  453.                         }
  454.                 }
  455.         if (byte == 0)  /* if true then there ain't no such beast */
  456.                 {
  457.                 portsout("Hmmm, can't seem to find that line");
  458.                 portsout(CRLF);
  459.                 portsout("   give me another chance, ok?");
  460.                 portsout(CRLF);
  461.                 return;         /* here we go round the mulberry bush */
  462.                 }
  463.  
  464.         portsout(CRLF);
  465.         portsout("Line to ") ;
  466.         if(tflag == 'E')
  467.                 { portsout("edit") ; }
  468.         else if(tflag == 'I')
  469.                 { portsout("insert after"); }
  470.         else if(tflag == 'D')
  471.                 {
  472.                 portsout("delete");
  473.                 }
  474.         else return ;
  475.  
  476.         portsout(" is:") ;
  477.         portsout(CRLF) ;
  478.         portsout(">") ;
  479.  
  480.         while(byte = *msg_ptr++)                /* show the line to edit */
  481.                 {
  482.                 if(tflag == 'I')
  483.                         {
  484.                         *work_ptr++ = byte ;    /* if adding new line copy */
  485.                         }
  486.                 if(byte == '\n') break ;
  487.                 portout(byte);
  488.                 }
  489.         portsout(CRLF) ;
  490.  
  491.         if(tflag == 'D')
  492.                 {
  493.                 portsout("Are you sure? (Y/N) ==> ");
  494.                 byte = portin() ;       /* get answer */
  495.                 portout(byte) ;         /* send it back */
  496.                 if ((byte != 'Y') && (byte != 'y')) return ;
  497.                 }
  498.         else
  499.                 {
  500.                 portsout("Enter new line:") ;
  501.                 portsout(CRLF) ;
  502.                 portsout(">") ;
  503.                 portsin(new_line,40) ;
  504.                 portsout(CRLF) ;
  505.                 strcat(new_line,"\n\0") ;               /* lf at end new line */
  506.                 while (*work_ptr++ = *new_ptr++)        /* tag on new line to */
  507.                         { ; }                           /*  work area */
  508.                 *work_ptr--;                            /* back up one */
  509.                 }
  510.  
  511.         while (*work_ptr++ = *msg_ptr++)        /* now move in rest of */
  512.                 { ; }                           /*  message to work area */
  513.         *work_ptr++ = '\0';             /* for luck */
  514.  
  515.         strcpy(msg_text,work_msg);      /* replace the message with the */
  516.                                         /*  new line inserted */
  517.         }
  518. /*      end of function         */
  519.  
  520. cmd_k()
  521.         {
  522.         char    ans[11];
  523.         int     kill_msg,
  524.                 fd,
  525.                 rc;
  526.  
  527.         portsout(CRLF) ;
  528.         portsout("Enter message number to delete ==> ") ;
  529.         portsin(ans,10) ;
  530.         portsout(CRLF) ;
  531.         kill_msg = atoi(ans) ;
  532.         fd = msgopen(2) ;               /* open i/o */
  533.         if ((rc = msgread(fd,kill_msg)) == ERROR || rc == 0)
  534.                 {
  535.                 portsout("Can't delete that message!") ;
  536.                 portsout(CRLF) ;
  537.                 return ;
  538.                 }
  539.         portsout("Deleting message...") ;
  540.         portsout(CRLF) ;
  541.         strcpy(msg_delete,"9") ;                /* mark for deletion */
  542.         if (msgrewrt(fd,kill_msg) == ERROR) /* re-write the record just read */
  543.                 {
  544.                 portsout("Sorry, can't delete that message");
  545.                 portsout(CRLF);
  546.                 return;
  547.                 }
  548.         msgclose(fd);
  549.         portsout("Message ");
  550.         portsout(ans);
  551.         portsout(" has been deleted!") ;
  552.         portsout(CRLF);
  553.         return;
  554.         }
  555. /*      end of function         */
  556.  
  557. cmd_q()
  558.         {
  559.         char    ans[11];
  560.         int     q_msg,
  561.                 fd,
  562.                 rc;
  563.  
  564.         if ((fd = msgopen(0)) == ERROR)         /* open input */
  565.                 {
  566.                 return(ERROR);
  567.                 }
  568.         portsout(CRLF);
  569.         portsout("Enter starting message number -- RETURN to exit  ==> ");
  570.         portsin(ans,10);
  571.         q_msg = atoi(ans);
  572.         if (q_msg == 0)                 /* = 0 all done */
  573.                 {
  574.                 msgclose(fd);
  575.                 return;
  576.                 }
  577.         portsout(CRLF);
  578.         portsout(CRLF);
  579.         portsout("No.      Date            Subject") ;
  580.         portsout(CRLF);
  581.         portsout("---------------------------------------");
  582.         portsout(CRLF);
  583.  
  584.         while ((rc = msgread(fd,q_msg++)) != ERROR)
  585.                 {                       /* read until eof or error */
  586.                 if (rc == 0)
  587.                         {
  588.                         continue;       /* not a valid msg */
  589.                         }
  590.                 portlsout(msg_no  , 6) ;
  591.                 portlsout(msg_date,12) ;
  592.                 portsout(msg_subject ) ;
  593.                 portsout(CRLF);
  594.                 if (stop_that)          /* ctl-K ? */
  595.                         {
  596.                         stop_that = FALSE;
  597.                         break;
  598.                         }
  599.                 }
  600.         msgclose(fd);
  601.         }
  602. /*      end of function         */
  603.  
  604. cmd_r()
  605.         {
  606.         char    msgno[10],
  607.                 *text,
  608.                 byte0;
  609.         int     msg,
  610.                 fd,
  611.                 rc;
  612.  
  613.         if ((fd = msgopen(0)) == ERROR)         /* open input */
  614.                 {
  615.                 return(ERROR);
  616.                 }
  617.         portsout("\r\n\n");
  618.         portsout("Enter the message number to read");
  619.         portsout(" - RETURN to exit   ==> ");
  620.  
  621.         while (!stop_that)
  622.                 {
  623.                 portsin(msgno,9);
  624.                 portsout(CRLF);
  625.                 msg = atoi(msgno);      /* make the no. integer */
  626.                 if (msg == 0)
  627.                         {
  628.                         break;
  629.                         }
  630.                 if ((rc = msgread(fd,msg)) == 0 || rc == ERROR)
  631.                         {
  632.                         portsout("Message ");
  633.                         portsout(msgno);
  634.                         portsout(" not found\r\n");
  635.                         }
  636.                 else
  637.                         {
  638.                         portsout(CRLF);
  639.                         portsout("No. ");
  640.                         portsout(msg_no);
  641.                         portsout("  ");
  642.                         portsout(msg_date);
  643.                         portsout("  ");
  644.                         portsout(msg_time);
  645.                         portsout(CRLF);
  646.  
  647.                         portsout("From: ");
  648.                         portsout(msg_from);
  649.                         portsout("   To: ");
  650.                         portsout(msg_to);
  651.                         portsout(CRLF);
  652.  
  653.                         portsout("Subject: ");
  654.                         portsout(msg_subject);
  655.                         portsout(CRLF);
  656.                         portsout(CRLF);
  657.  
  658.                         text = msg_text;
  659.                         while (byte0 = (*text++))
  660.                                 {
  661.                                 if (byte0 == '\n')
  662.                                         {
  663.                                         portout('\r');
  664.                                         }
  665.                                 portout(byte0);
  666.                                 if (stop_that)
  667.                                         {
  668.                                         stop_that = FALSE;
  669.                                         msgclose(fd);
  670.                                         return;
  671.                                         }
  672.                                 }
  673.                         }
  674.                 portsout(CRLF);
  675.                 portsout("Number or RETURN to exit ==> ") ;
  676.                 }
  677.         msgclose(fd);
  678.         }
  679. /*      end of function         */
  680.  
  681. cmd_s()
  682.         {
  683.         char    ans[11];
  684.         int     q_msg,
  685.                 fd,
  686.                 rc;
  687.  
  688.         if ((fd = msgopen(0)) == ERROR)         /* open input */
  689.                 {
  690.                 return(ERROR);
  691.                 }
  692.         portsout(CRLF);
  693.         portsout("Enter starting message number -- RETURN to exit ) ==> ") ;
  694.         portsin(ans,10);
  695.         q_msg = atoi(ans);
  696.         if (q_msg == 0)
  697.                 {
  698.                 return;
  699.                 }
  700.         portsout(CRLF);
  701.         portsout(CRLF);
  702.         portsout("No.     Date          From         ") ;
  703.         portsout("      To                    Subject") ;
  704.         portsout(CRLF);
  705.         portsout("---------------------------------------") ;
  706.         portsout("---------------------------------------") ;
  707.         portsout(CRLF);
  708.  
  709.         while ((rc = msgread(fd,q_msg++)) != ERROR)
  710.                 {                       /* read until eof or error */
  711.                 if (rc == 0)
  712.                         {
  713.                         continue;       /* not a valid msg */
  714.                         }
  715.                 portlsout(msg_no  , 6) ;
  716.                 portlsout(msg_date,12) ;
  717.                 portlsout(msg_from,21) ;
  718.                 portlsout(msg_to  ,21) ;
  719.                 portsout(msg_subject)  ;
  720.                 portsout(CRLF);
  721.                 if (stop_that)
  722.                         {
  723.                         stop_that = FALSE;
  724.                         break;
  725.                         }
  726.                 }
  727.         msgclose(fd);
  728.         }
  729. /*      end of function         */
  730.  
  731. cmd_x()
  732.         {
  733.         xpert = !xpert;         /* flip the expert mode */
  734.         }
  735. /*      end of function         */
  736.  
  737. cmd_p(name) char *name ;        /* type a file */
  738.         {
  739.         if ((inbuf=fopen(name,"r")) == NULL)
  740.                 {
  741.                 portsout("\r\nSorry, needed file not available\r\n");
  742.                 }
  743.         else
  744.                 {
  745.                 porttype(inbuf);        /* type a file to port */
  746.                 close(inbuf);           /* close it to free up fcb */
  747.                 }
  748.         }
  749. /*      end of function         */
  750.  
  751. signon()        
  752.         {
  753.         char    byte0 ;
  754.  
  755.         int     i ;
  756.         int     tfd ;
  757.  
  758.         portsout(PGMNAME)   ;
  759.         portsout("Version") ;
  760.         portsout(VERSION)   ;
  761.         portsout(LASTDATE)  ;
  762.         portsout(CRLF)      ;
  763. /*
  764. *                       type welcome file
  765. */
  766.         if ((inbuf=fopen(WELCOME,"r")) == NULL)
  767.                 {
  768.                 portsout(CRLF) ;
  769.                 portsout("Welcome file not present, welcome anyhow!") ;
  770.                 portsout(CRLF) ;
  771.                 }
  772.         else
  773.                 {
  774.                 porttype(inbuf);        /* type a file to port */
  775.                 close(inbuf);
  776.                 }
  777.         portsout("On at ");     /* give date and time of signon */
  778.         portsout(ttime);
  779.         portsout("  ");
  780.         portsout(week);
  781.         portsout("  ");
  782.         portsout(date);
  783. /*
  784. *                       get name
  785. */
  786.         while (1)
  787.                 {
  788.                 portsout("\r\n\n");
  789.                 portsout("Enter your first name   ==> ");
  790.                 portsin(w_fname,20);
  791.                 fix_name(w_fname) ;
  792.                 portsout(CRLF);
  793.                 portsout("Enter your last name    ==> ");
  794.                 portsin(w_lname,20);
  795.                 fix_name(w_lname) ;
  796.                 portsout("\r\r\n");
  797.                 portsout("Hello ");
  798.                 portsout(w_fname);
  799.                 portsout(" ");
  800.                 portsout(w_lname);
  801.                 portsout(CRLF);
  802.                 portsout("Did I get your name right?  (Y/N) ==> ");
  803.                 byte0 = portin();       /* get answer */
  804.                 portout(byte0);         /* send it back */
  805.                 if ((byte0 == 'Y') || (byte0 == 'y'))
  806.                         {
  807.                         portsout(CRLF) ;
  808.                         wcaller() ;
  809.                         if (checkuser())
  810.                                 {
  811.                                 break ; /* got a valid user */
  812.                                 }
  813.                         else
  814.                                 {
  815.                                 return ; /* do not have a valid user */
  816.                                 }
  817.                         }
  818.                 }
  819. /*
  820. *                       type bulletins file
  821. */
  822.         if ((inbuf=fopen(BULLETINS,"r")) == NULL)
  823.                 {
  824.                 portsout("\r\nNo Bulletins today\r\n");
  825.                 }
  826.         else
  827.                 {
  828.                 porttype(inbuf);        /* type a file to port */
  829.                 close(inbuf);
  830.                 }
  831.  
  832.         hdrread();              /* read msgs header file into memory */
  833. /*
  834. *                       end of signon
  835. */
  836.  
  837.         }
  838. /*      end of function         */
  839.                 
  840. fix_name(adr) char *adr ;
  841.         {
  842.         char *adrs ;
  843.         adrs = adr ;
  844.         while(*adrs)
  845.                 {
  846.                 *adrs = tolower(*adrs) ;
  847.                 adrs++ ;
  848.                 }
  849.         *adr = toupper(*adr) ;
  850.         }
  851.  
  852. wcaller()   /* added this caller to the caller file */
  853.         {
  854.         int     code ;
  855.         char    l_date[80] ;
  856.  
  857.         strcpy(l_date,  mm) ;
  858.         strcat(l_date, "/") ;
  859.         strcat(l_date,  dd) ;
  860.         strcat(l_date, "/") ;
  861.         strcat(l_date,  yy) ;
  862.  
  863.         if ((inbuf=fopen(CALLERS,"a")) == NULL) /* create or open for append */
  864.                 {
  865.                 portsout(CRLF) ;
  866.                 portsout("Can't open/create callers file!");
  867.                 portsout(CRLF) ;
  868.                 return ;
  869.                 }
  870.         code = fprintf(inbuf,"%s %s %s %s",l_date,ttime,w_fname,w_lname) ;
  871.         if (code < 0)
  872.                 {
  873.                 portsout(CRLF) ;
  874.                 portsout("Caller file has problem writing") ;
  875.                 portsout(CRLF) ;
  876.                 }
  877.         else
  878.                 {
  879.                 fputs("\n",inbuf) ;     /* put lf on end of each record */
  880.                 }
  881.         fclose(inbuf) ;
  882.         /* now also save caller as last-caller */
  883.         if ((inbuf=fopen(LASTCALL,"w")) == NULL) /* create or open for write */
  884.                 {
  885.                 portsout(CRLF) ;
  886.                 portsout("Can't open/create last-caller file!");
  887.                 portsout(CRLF) ;
  888.                 return ;
  889.                 }
  890.         code = fprintf(inbuf,"%s %s %s %s",l_date,ttime,w_fname,w_lname) ;
  891.         if (code < 0)
  892.                 {
  893.                 portsout(CRLF) ;
  894.                 portsout("Last-caller file has problem writing") ;
  895.                 portsout(CRLF) ;
  896.                 }
  897.         else
  898.                 {
  899.                 fputs("\n",inbuf) ;     /* put lf on end of record */
  900.                 }
  901.         fclose(inbuf) ;
  902.         }
  903. /*      end of function         */
  904.  
  905. checkuser()                     /* returns 1 when find a match */
  906.         {
  907.         char    name[50] ;
  908.  
  909.         if ((inbuf=fopen(USERS,"r")) == NULL)
  910.                 {
  911.                 portsout(CRLF) ;
  912.                 portsout("User file not present, will log you on as");
  913.                 portsout(" a GUEST!");
  914.                 portsout(CRLF) ;
  915.                 strcpy(u_fname,"GUEST");
  916.                 strcpy(u_lname," ");
  917.                 strcpy(u_password,"MPK0");
  918.                 return(TRUE);
  919.                 }
  920.  
  921.         portsout(CRLF) ;
  922.         portsout("Checking user file...");
  923.         portsout(CRLF) ;
  924.  
  925.         while (readuser(inbuf) != 0)    /* look until eof on users file */
  926.                 {
  927.                 if ((strcmp(u_fname,w_fname) == 0) &&
  928.                     (strcmp(u_lname,w_lname) == 0))
  929.                         {
  930.                         if (checkpass() == OK)
  931.                                 {
  932.                                 fclose(inbuf) ;
  933.                                 return(TRUE)  ; /* passwords match */
  934.                                 }
  935.                         else
  936.                                 {
  937.                                 fclose(inbuf) ;
  938.                                 return(FALSE) ; /* passwords dont match */
  939.                                 }
  940.                         }
  941.                 }
  942.         fclose(inbuf) ;
  943.         newuser() ;             /* not on file, so add 'em */
  944. /*
  945. *                       type new-user file
  946. */
  947.         if ((inbuf=fopen(NEWUSER,"r")) != NULL)
  948.                 {
  949.                 porttype(inbuf) ;       /* type a file to port */
  950.                 close(inbuf) ;
  951.                 }
  952.         return(TRUE) ;
  953.         }
  954. /*      end of function         */
  955.  
  956. checkpass()                     /* returns TRUE (1) when equal passwords */
  957.         {
  958.         char    *passptr;
  959.         int     j,
  960.                 i;
  961.  
  962.         passptr = w_password;   /* give passptr the addr of w_password */
  963.  
  964.         for (i = 0; i < 3; i++)         /* give 'em 3 tries to get it right */
  965.                 {
  966.                 portsout(CRLF) ;
  967.                 portsout("Enter your password  ==> ") ;
  968.                 for (j=0; j < 4; j++)   /* password is 4 long */
  969.                         {
  970. /*                      *passptr++ = portin() ;
  971. */
  972.                         w_password[j] = portin() ;
  973.                         portout('_');
  974.                         }
  975. /*              *passptr++ = '\0';
  976. */
  977.                 w_password[j] = '\0';
  978.  
  979.                 if ((strcmp(w_password,u_password)) == 0)
  980.                         {
  981.                         return(OK);     /* passwords match */
  982.                         }
  983.                 portsout(" Incorrect!\007") ;
  984.                 }
  985.         if (i >= 3)
  986.                 {
  987.                 portsout(CRLF) ;
  988.                 portsout("Sorry, but three tries is all you get!") ;
  989.                 portsout(CRLF) ;
  990.                 portsout("  Goodby....") ;
  991.                 cmd_g()        ;            /* hang up the phone   */
  992.                 portsout(CRLF) ;
  993.                 return(ERROR);              /* bad try on password */
  994.                 }
  995.         }
  996. /*      end of function         */
  997.  
  998. newuser()
  999.         {
  1000.         char    pword[5];
  1001.         int     j;
  1002.  
  1003.         if ((inbuf=fopen(USERS,"a")) == NULL)
  1004.                 {
  1005.                 portsout(CRLF) ;
  1006.                 portsout("Can't open/create the user file for writing!") ;
  1007.                 portsout(CRLF) ;
  1008.                 return ;
  1009.                 }
  1010.  
  1011.         strcpy(u_fname,w_fname);
  1012.         strcpy(u_lname,w_lname);
  1013.  
  1014.         strcpy(u_time1,ttime);
  1015.         strcpy(u_time2,ttime);
  1016.  
  1017.         strcpy(u_date1,mm);
  1018.         strcat(u_date1,"/");
  1019.         strcat(u_date1,dd);
  1020.         strcat(u_date1,"/");
  1021.         strcat(u_date1,yy);
  1022.  
  1023.         strcpy(u_date2,mm);
  1024.         strcat(u_date2,"/");
  1025.         strcat(u_date2,dd);
  1026.         strcat(u_date2,"/");
  1027.         strcat(u_date2,yy);
  1028.  
  1029.         portsout(CRLF) ;
  1030.         portsout("Welcome, as a new user I need a few pieces") ;
  1031.         portsout(" of information.") ;
  1032.         portsout(CRLF) ;
  1033.         portsout(CRLF) ;
  1034.  
  1035.         portsout("Please enter the City, State you are from ===> ");
  1036.         portsin(u_city,30);
  1037.         portsout(CRLF);
  1038.  
  1039.         while (1)
  1040.                 {
  1041.                 portsout(CRLF) ;
  1042.                 portsout("Ok, now I need a 4 character password ===> ");
  1043.                 for (j=0; j < 4; j++)   /* password is 4 long */
  1044.                         {
  1045.                         u_password[j] = portin();
  1046.                         portout('_');
  1047.                         }
  1048.                 u_password[j] = '\0';
  1049.                 portsout(CRLF) ;
  1050.  
  1051.                 portsout("Just to make sure, enter it again ===> ");
  1052.                 for (j=0; j < 4; j++)   /* password is 4 long */
  1053.                         {
  1054.                         w_password[j] = portin();
  1055.                         portout('_');
  1056.                         }
  1057.                 w_password[j] = '\0';
  1058.                 portsout(CRLF) ;
  1059.  
  1060.                 if (strcmp(u_password,w_password) == 0)
  1061.                         {
  1062.                         break ; /* get it right twice, then get out */
  1063.                         }
  1064.                 portsout(CRLF) ;
  1065.                 portsout("hmmmm, one of us forgot it already") ;
  1066.                 portsout(CRLF) ;
  1067.                 portsout("    let's try it again!!") ;
  1068.                 portsout(CRLF) ;
  1069.                 portsout(CRLF) ;
  1070.                 }
  1071.  
  1072.         wrtuser(inbuf) ;        /* write a user record */
  1073.         fflush(inbuf)  ;        /* ok leor, just for you */
  1074.         fclose(inbuf)  ;        /* close the file after new user added */
  1075.         }
  1076. /*      end of function         */
  1077.  
  1078. readuser(buf)   /* read a record from the user file */
  1079.                 /*  returns 0 on eof, 1 on good read */
  1080. FILE    *buf;
  1081.         {
  1082.         int     code;
  1083.  
  1084.         code = fscanf(buf,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~\n",
  1085.                         u_fname,
  1086.                         u_lname,
  1087.                         u_password,
  1088.                         u_time1,
  1089.                         u_date1,
  1090.                         u_time2,
  1091.                         u_date2,
  1092.                         u_city);
  1093.  
  1094.         if (code < 8)
  1095.                 {
  1096.                 return(0);      /* all done, hit eof */
  1097.                 }
  1098.         else
  1099.                 {
  1100.                 return(1);      /* good read */
  1101.                 }
  1102.         }
  1103. /*      end of function         */
  1104.  
  1105. wrtuser(buf)
  1106. FILE    *buf;
  1107.         {
  1108.         int     code;
  1109.         code = fprintf(buf,"%s~%s~%s~%s~%s~%s~%s~%s~",
  1110.                         u_fname,
  1111.                         u_lname,
  1112.                         u_password,
  1113.                         u_time1,
  1114.                         u_date1,
  1115.                         u_time2,
  1116.                         u_date2,
  1117.                         u_city);
  1118.         if (code == -1)
  1119.                 {
  1120.                 portsout("User file has problem writing\r\n");
  1121.                 }
  1122.         else
  1123.                 {
  1124.                 fputs("\n",buf);        /* put lf on end of each record */
  1125.                 }
  1126.         }
  1127. /*      end of function         */
  1128.  
  1129. /*      end of program          */
  1130. \n");
  1131.         }
  1132.     else
  1133.         {
  1134.         fputs("\n",buf);    /* put lf on end of each record */
  1135.